home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / TECHNICA / COMPUTER / H254.ZIP / IRITSM3S.ZIP / MISC_LIB / IRITPRSR.H < prev    next >
C/C++ Source or Header  |  1992-01-28  |  5KB  |  131 lines

  1. /*****************************************************************************
  2. * Generic parser for the "Irit" solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Sep. 1991   *
  5. *****************************************************************************/
  6.  
  7. #ifndef    IRIT_PRSR_GH
  8. #define    IRIT_PRSR_GH
  9.  
  10. #include "cagd_lib.h"
  11. #include "genmat.h"
  12.  
  13. typedef enum {
  14.     IP_POLYGON = 1,
  15.     IP_POLYLINE,
  16.     IP_POINTLIST
  17. } IPPolyStructType;
  18.  
  19. typedef enum {
  20.     IP_OBJ_UNDEF,
  21.     IP_OBJ_POLY,
  22.     IP_OBJ_SURFACE,
  23.     IP_OBJ_CURVE
  24. } IPObjStructType;
  25.  
  26. #define MAX_NUM_ATTRS        10
  27.  
  28. /*****************************************************************************
  29. * Attributes - an attribute is a pair of strings consists of a key and the   *
  30. * data. Up to MAX_NUM_ATTRS are supported.                             *
  31. *****************************************************************************/
  32. typedef struct IPAttributeStruct {
  33.     int NumStrAttribs;
  34.     char *StrAttrName[MAX_NUM_ATTRS];            /* Generic string attrs. */
  35.     char *StrAttrData[MAX_NUM_ATTRS];
  36. } IPAttributeStruct;
  37.  
  38.  
  39. #define IP_IS_VRTX_INTERNAL(V)        (V -> VTags & 0x01)
  40. #define IP_SET_VRTX_INTERNAL(V)        (V -> VTags |= 0x01)
  41. #define IP_RST_VRTX_INTERNAL(V)        (V -> VTags &= ~0x01)
  42. #define IP_HAS_VRTX_NORMAL(V)        (V -> VTags & 0x02)
  43. #define IP_SET_VRTX_NORMAL(V)        (V -> VTags |= 0x02)
  44. #define IP_RST_VRTX_NORMAL(V)        (V -> VTags &= ~0x02)
  45.  
  46. typedef struct IPVertexStruct {
  47.     struct IPVertexStruct *Pnext;                /* To next in chain. */
  48.     VoidPtr VAux;
  49.     unsigned int VTags;                     /* Some attributes. */
  50.     int Color;
  51.     RealType Coord[3];                   /* Holds X, Y, Z coordinates. */
  52.     RealType Normal[3];               /* Hold Vertex normal into the solid. */
  53. } IPVertexStruct;
  54.  
  55. #define IP_HAS_POLY_PLANE(P)        (P -> PTags & 0x01)
  56. #define IP_SET_POLY_PLANE(P)        (P -> PTags |= 0x01)
  57. #define IP_RST_POLY_PLANE(P)        (P -> PTags &= ~0x01)
  58. #define IP_HAS_POLY_BBOX(P)        (P -> PTags & 0x02)
  59. #define IP_SET_POLY_BBOX(P)        (P -> PTags |= 0x02)
  60. #define IP_RST_POLY_BBOX(P)        (P -> PTags &= ~0x02)
  61.  
  62. typedef struct IPPolygonStruct {
  63.     struct IPPolygonStruct *Pnext;                /* To next in chain. */
  64.     VoidPtr PAux;
  65.     unsigned int PTags;                         /* Some attributes. */
  66.     IPPolyStructType Type;
  67.     RealType Plane[4];             /* Holds Plane as Ax + By + Cz + D. */
  68.     RealType Xmin, Xmax, Ymin, Ymax;         /* Bounding box of the polygon. */
  69.     IPVertexStruct *PVertex;                    /* To vertices list. */
  70. } IPPolygonStruct;
  71.  
  72. #define IP_HAS_OBJ_RGB(P)        (P -> OTags & 0x01)
  73. #define IP_SET_OBJ_RGB(P)        (P -> OTags |= 0x01)
  74. #define IP_RST_OBJ_RGB(P)        (P -> OTags &= ~0x01)
  75. #define IP_HAS_OBJ_COLOR(P)        (P -> OTags & 0x02)
  76. #define IP_SET_OBJ_COLOR(P)        (P -> OTags |= 0x02)
  77. #define IP_RST_OBJ_COLOR(P)        (P -> OTags &= ~0x02)
  78.  
  79. typedef struct IPObjectStruct {
  80.     struct IPObjectStruct *Pnext;
  81.     struct IPObjectStruct *FFPolylines, *FFPolygons;    /* Freeform approx.. */
  82.     struct IPAttributeStruct Attrs;
  83.     VoidPtr OAux;
  84.     char Name[OBJ_NAME_LEN];
  85.     unsigned char RGB[3];
  86.     unsigned int OTags;                         /* Some attributes. */
  87.     IPObjStructType Type;
  88.     int Color;
  89.     union {
  90.     IPPolygonStruct *PPolygon;
  91.     CagdCrvStruct *PCrvs;
  92.     CagdSrfStruct *PSrfs;
  93.     } U;
  94. } IPObjectStruct;
  95.  
  96. #if defined(__cplusplus) || defined(c_plusplus)
  97. extern "C" {
  98. #endif
  99. IPObjectStruct *IritPrsrGetObjects(FILE *f);
  100. int IritPrsrParseError(char **ErrorMsg);
  101. IPVertexStruct *IritPrsrNewVertexStruct(void);
  102. IPPolygonStruct *IritPrsrNewPolygonStruct(void);
  103. IPObjectStruct *IritPrsrNewObjectStruct(void);
  104.  
  105. void IritPrsrSetStrAttrib(IPObjectStruct *PObj, char *Name, char *Data);
  106. char *IritPrsrGetStrAttrib(IPObjectStruct *PObj, char *Name);
  107.  
  108. /* If set to TRUE (default) polygons will have their vertex lists circular   */
  109. /* or last vertex point on first. If set to FALSE, regular list list.         */
  110. extern int IritPrsrPolyListCirc;
  111.  
  112. /* Will be set to VIEW_MAT and PERS_MAT respectively if found in parsed data.*/
  113. extern MatrixType IritPrsrViewMat, IritPrsrPrspMat;
  114. extern int IritPrsrWasViewMat, IritPrsrWasPrspMat;
  115.  
  116. /* External variables/functions that should be provided by the application:  */
  117.  
  118. /* Gets two list of all curves and surfaces in the datafile and process them */
  119. /* as needed. May return a processed version to be put on returned list from */
  120. /* IritPrsrGetObjects (polygonal approximation of the free form data for     */
  121. /* example), or NULL otherwise.                             */
  122. /* This function is responsible to free crvs/srfs if not needed any more.    */
  123. IPObjectStruct *IritPrsrProcessFreeForm(IPObjectStruct *CrvObjs,
  124.                     IPObjectStruct *SrfObjs);
  125.  
  126. #if defined(__cplusplus) || defined(c_plusplus)
  127. }
  128. #endif
  129.  
  130. #endif    /* IRIT_PRSR_GH */
  131.